package com.ysl.study.designpattern.createmode.singleton;

/**
 * 单例模式 懒汉模式 枚举
 *
 * @author yangshanlin
 * @date 2023/2/16 18:12
 * @describe
 */
public class Singleton6 {
    private Singleton6(){}

    private static Singleton6 single = null;

    public static Singleton6 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton{
        INSTANCE;
        private Singleton6 singleton;
        //JVM会保证此方法绝对只调用一次
        private Singleton(){
            singleton = new Singleton6();
        }
        public Singleton6 getInstance(){
            return singleton;
        }
    }

}
